package com.zbaohuang.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;
import com.zbaohuang.model.WarningModel;
import com.zbaohuang.xyh.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

public class WarningFragment extends Fragment {

    ListView listView;
    List<WarningModel> warningModelList;

    View rootView;
    QuickAdapter<WarningModel> quickAdapter;

    public WarningFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_warning, container, false);
        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initData();
        listView = ButterKnife.findById(rootView, R.id.listView);

        quickAdapter = new QuickAdapter<WarningModel>(getActivity(),R.layout.item_warning) {
            @Override
            protected void convert(BaseAdapterHelper helper, WarningModel item) {

                helper.setText(R.id.contentTextView,item.getContent());
                helper.setText(R.id.datetimeTextView,item.getDatetime());

                if (item.getPosition() == 0){
                    helper.setVisible(R.id.layout1,true);
                    helper.setImageResource(R.id.imageView1, R.mipmap.shuaidao1);
                    helper.setImageResource(R.id.imageView2,R.mipmap.shuaidao2);
                    helper.setImageResource(R.id.imageView3,R.mipmap.shuaidao1);
                } else if(item.getPosition() == 1){
                    helper.setVisible(R.id.layout1,true);
                    helper.setImageResource(R.id.imageView1, R.mipmap.moshengren1);
                    helper.setImageResource(R.id.imageView2,R.mipmap.moshengren2);
                    helper.setImageResource(R.id.imageView3,R.mipmap.moshengren1);
                } else if(item.getPosition() == 2){
                    helper.setVisible(R.id.layout1, true);
                    helper.setImageResource(R.id.imageView1, R.mipmap.chuzou1);
                    helper.setImageResource(R.id.imageView2,R.mipmap.chuzou2);
                    helper.setImageResource(R.id.imageView3, R.mipmap.chuzou3);
                } else if(item.getPosition() == 3){
                    helper.setVisible(R.id.layout1, false);
                } else if(item.getPosition() == 4){
                    helper.setVisible(R.id.layout1, false);
                } else if(item.getPosition() == 5){
                    helper.setVisible(R.id.layout1, false);
                }


            }
        };
        listView.setAdapter(quickAdapter);
        quickAdapter.addAll(warningModelList);
    }

    private void initData(){
        warningModelList = new ArrayList<WarningModel>();
        warningModelList.add(new WarningModel(0,"红红助手","2016-04-05 13:22","亲爱的黄先生，刚刚系统监测到家中有人摔倒了，请你及时查看并处理，以免意外发生...",""));
        warningModelList.add(new WarningModel(1,"红红助手","2016-04-03 10:20","亲爱的黄先生，刚刚系统监测到您的家里有陌生人进入到房间里，请及时查看处理，以免意外发生...",""));
        warningModelList.add(new WarningModel(2,"红红助手","2016-04-01 16:40","亲爱的黄先生，刚刚系统监测到您的父亲外出长时间未归，请及时联系，以免意外发生...",""));
        warningModelList.add(new WarningModel(3,"红红助手","2016-03-30 08:30","亲爱的黄先生，刚刚系统监测到你的母亲心率有点异常，请留意",""));
        warningModelList.add(new WarningModel(4,"红红助手","2016-03-30 08:30","亲爱的黄先生，刚刚系统监测到你的父亲体温已经达到38.5度了，请及时送医，以免意外发生",""));
        warningModelList.add(new WarningModel(5,"红红助手","2016-03-30 08:30","亲爱的黄先生，刚刚系统监测到你的母亲血压最高值170kpa,请留意并提醒您的母亲要注意！",""));
    }
}
